package com.yungu.swift.order.thread.socket;


import com.yungu.swift.assets.driver.model.dto.DriverDto;
import com.yungu.swift.constants.MagicConstant;
import com.yungu.swift.order.model.dto.OrderDetailDto;
import com.yungu.swift.order.utils.SendMessageUtils;
import com.yungu.swift.socket.push.service.PushService;

/**
 * Created by cuixiuyin on 2018/3/20.
 */
public class CyclePushMessage extends Thread {

    private PushService pushService;
    private DriverDto driverDto;
    private OrderDetailDto orderDetailDto;
    private String mobile;

    public CyclePushMessage(PushService pushService, DriverDto driverDto, OrderDetailDto orderDetailDto, String mobile) {
        this.pushService = pushService;
        this.driverDto = driverDto;
        this.orderDetailDto = orderDetailDto;
        this.mobile = mobile;
    }

    @Override
    public void run() {
        if (driverDto.getMobile() == null || mobile == null) {
            return;
        }
        //司机142开头的测试账号，就不发送短信
        if (driverDto.getMobile().startsWith(MagicConstant.STRING_ONE_FOUR_TWO)) {
            return;
        }
        // 长连接通道存在就不发短信
        if (pushService.getChannel(driverDto.getUuid()).getData()) {
            return;
        }
        SendMessageUtils.assignDriverSend(driverDto, orderDetailDto, mobile);
    }
}
